package com.fjw.controller;

import com.fjw.pojo.Claz;
import com.fjw.service.ClazService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author fjw
 * @version 1.0
 * @date 2019/11/1 16:50
 */
@Controller
@Slf4j
public class ClazController {

    @Autowired
    private ClazService clazService;

    @GetMapping("listClaz")
    public String listClaz(Model model){
        List<Claz> clazList = clazService.listClaz();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        for (Claz claz : clazList) {
            String format = simpleDateFormat.format(claz.getCreateTime());
            claz.setTime(format);
        }
        model.addAttribute("clazList",clazList );
        //跳转到显示界面
        return "forward:/index.jsp";
    }
    /**
     * 增加班级
     */
    @PostMapping("/addClaz")
    public String addClaz(Claz claz,Model model){
        //
        Integer integer = clazService.addClaz(claz);
        log.info("integer:{}"+integer);
        //挑战到显示班级界面
        return listClaz(model);
    }

}
